<?php
namespace Admin\Controller;
use Think\Controller;

class ArticleController extends Controller{
    public function index(){
        $this->display();
    }

    public function add(){
        $category = D('category');
        $c = $category->where('type = 1')->select();
        $this->assign('c',$c);
        $tag = C('WEB_TAG');
        $tags = explode(',',$tag);
        $this->assign('tags',$tags);
        print_r($tags);
        $this->display();
    }
    public function doadd(){
        $article = D('article');
        $data = $article->create();
        $data['time'] = time();
        if ($_FILES['pic']['tmp_name'] != '') {
            $upload = new \Think\Upload();
            $upload->maxSize = 3145728;
            $upload->exts = array('jpg', 'gif', 'png', 'jpeg');
            $upload->rootPath = './Uploads/';
            $upload->savePath = '/';
            $info = $upload->uploadOne($_FILES['pic']);
            if (!$info) {
                $this->error($upload->getError());
            } else {
                $data['pic'] = $info['savepath'] . $info['savename'];
            }
        }
        $result = $article->add($data);
        if($result >0 ){
            $this->success('添加成功！',U('index'));
        }else{
            $this->error('添加失败！');
        }

    }

}